package net.vkits.admin.application;

import net.vkits.admin.domain.model.Rate;
import net.vkits.admin.domain.repository.RateRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by ethan-liu on 2017/1/14.
 */
@Service
public class RateApplicationService {
    private static final Logger logger = LoggerFactory.getLogger(RateApplicationService.class);

    @Resource
    private RateRepository rateRepository;

    public Page<Rate> getRates(Pageable pageable) {
        return rateRepository.findAll(pageable);
    }

    public Rate getRate() {
        return rateRepository.findOne(1L);
    }

    public void modifyRate(Rate rate) {
        Rate r = rateRepository.findOne(rate.getId());
        r.setRate(rate.getRate());
        r.setVipRate(rate.getVipRate());
        rateRepository.save(r);
    }
}
